package com.n9.qq.android.login;

import com.n9.qq.android.Const;
import com.n9.qq.android.login.BaseReqLoginBody;
import com.n9.qq.android.login.tlv.*;
import com.n9.qq.util.Crypter;

import java.nio.ByteBuffer;

/**
 * @author ice
 * @since 2019/2/19 14:19
 */
public class ReqGetSmsCode extends BaseReqLoginBody{

    int cmd = 0x08;
    private byte[] imgToken;
    private byte[] smsToken;

    public ReqGetSmsCode(long qqUin, byte[] imgToken, byte[] smsToken) {
        this.qqUin = qqUin;
        this.imgToken = imgToken;
        this.smsToken = smsToken;
    }

    @Override
    protected byte[] encryptData(byte[] shareKey) {
        Tlv0008 tlv0008 = new Tlv0008();
        byte[] ds0008Data = tlv0008.getData(0, 0x00000804, 0);
        Tlv0104 tlv0104 = new Tlv0104();
        byte[] ds0104Data = tlv0104.getData(imgToken);
        Tlv0116 tlv0116 = new Tlv0116();
        byte[] ds0116Data = tlv0116.getData(Const.M_MISC_BIT_MAP, Const.M_SUB_SIG_MAP, null);
        Tlv0174 tlv0174 = new Tlv0174();
        byte[] ds0174Data = tlv0174.getData(smsToken);
        Tlv017A tlv017a = new Tlv017A();
        byte[] ds017aData = tlv017a.getData(0x09);
        Tlv0197 tlv0197 = new Tlv0197();
        byte[] ds0197Data = tlv017a.getData(0x00);

        int len = ds0008Data.length + ds0104Data.length + ds0116Data.length + ds0174Data.length + ds017aData.length + ds0197Data.length + 4;
        ByteBuffer buf = ByteBuffer.allocate(len);
        buf.putShort((short)cmd);
        buf.putShort((short)6);
        buf.put(ds0008Data);
        buf.put(ds0104Data);
        buf.put(ds0116Data);
        buf.put(ds0174Data);
        buf.put(ds017aData);
        buf.put(ds0197Data);

        return new Crypter().encrypt(buf.array(), shareKey);
    }
}
